<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>生成福字海报</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/img_text.css">
    <link rel="stylesheet" href="${ctx}/static/uploadCI/upload.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
    <link rel="stylesheet" href="${ctx}/css/ui/mall/goods_form.css">
    <link rel="stylesheet" href="${ctx}/css/form-preview.css">
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post"
                      action="${ctx}/PosterController/createFuzPoster.do">
                    <div class="layui-form-item">
                        <div class="layui-form-item">
                            <label class="layui-form-label">众筹者昵称<span class="f-verify-red">*</span></label>
                            <div class="layui-input-block">
                                <input type="text" name="memberUsername" id="memberUsername" lay-verify="memberUsername"
                                       autocomplete="off"
                                       class="layui-input" value=""
                                       style="width: 200px; float: left; margin-right: 10px;">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">众筹者头像链接<span class="f-verify-red">*</span></label>
                            <div class="layui-input-block">
                                <input type="text" name="logo" id="logo" lay-verify="logo"
                                       autocomplete="off"
                                       class="layui-input" value=""
                                       style="width: 200px; float: left; margin-right: 10px;">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">二维码链接链接<span class="f-verify-red">*</span></label>
                            <div class="layui-input-block">
                                <input type="text" name="qccode" id="qccode" lay-verify="qccode"
                                       autocomplete="off"
                                       class="layui-input" value=""
                                       style="width: 200px; float: left; margin-right: 10px;">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit
                                   lay-filter="*">立即生成</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <%@include file="../include/footer.jsp" %>
    </section>
</div>
<script>

    var form, laydate, formcache;
    $(function () {
        layui.use(['form', 'laydate'], function () {
            form = layui.form, laydate = layui.laydate;

            //自定义验证规则
            form.verify({
                memberUsername: function (value) {
                    if (value.trim() == "") {
                        return '众筹者昵称不能为空';
                    }
                },
                logo: function (value) {
                    if (value.trim() == "") {
                        return "众筹者头像链接不能为空";
                    }
                },
                qccode: function (value) {
                    if (value.trim() == "") {
                        return "二维码链接不能为空";
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                submitForm(data);
            });

        });
    });

    function getFormData() {
        var formData = util.serializeForm($('#myForm').serializeArray());
        return formData;
    }


    function submitForm(data) {


        txz.submitObject(data.elem, function (callBack) {
            var loadIndex = top.layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });


            var formData = getFormData();
            var action = $("#myForm").attr("action");
            txz.ajaxRequest({
                method: 'post',
                url: action,
                saveCache: true,
                cacheObj: formcache,
                params: formData,
                callBack: function (suc) {
                    top.layer.close(loadIndex);

                    if (suc.success == true) {
                        var posterUrl = suc.description;
                        if (posterUrl.trim() == "") {
                            util.layerAlertError("海报生成失败,请稍等一会")
                        } else {
                            util.layerAlertSuccess("海报生成成功", function () {
                                window.open(posterUrl);
                                window.location.reload();
                            })

                        }
                    } else {
                        util.layerAlertError(suc.description)
                    }
                }
            });

        })
    }


</script>
</body>
</html>